package com.heima.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.admin.mapper.AdAuthMapper;
import com.heima.admin.service.AdAuthService;
import com.heima.model.admin.dtos.AdAuthDto;
import com.heima.model.admin.pojos.AdUser;
import com.heima.model.admin.pojos.ApUserRealname;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class AdAuthServiceImpl extends ServiceImpl<AdAuthMapper, ApUserRealname> implements AdAuthService {

    /**
     * 查询用户列表
     * @param dto
     * @return
     */
    @Override
    public ResponseResult findList(AdAuthDto dto) {

        //检查参数
        dto.checkParam();

        //分页查询
        IPage page = new Page(dto.getPage(), dto.getSize());

        //构建查询条件
        LambdaQueryWrapper<ApUserRealname> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if(dto.getId() != null) {
            lambdaQueryWrapper.eq(ApUserRealname::getId, dto.getId());
        }
        if(dto.getStatus() != null) {
            lambdaQueryWrapper.eq(ApUserRealname::getStatus, dto.getStatus());
        }
        lambdaQueryWrapper.orderByDesc(ApUserRealname::getUpdatedTime);

        page = page(page, lambdaQueryWrapper);
        ResponseResult responseResult = new PageResponseResult(dto.getPage(), dto.getSize(), (int)page.getTotal());
        responseResult.setData(page.getRecords());
        return responseResult;
    }
}
